<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>假日管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link href="__PUBLIC__/css/layui.css" rel="stylesheet" type="text/css"/>
    <link href="__PUBLIC__/css/admin.css" rel="stylesheet" type="text/css"/>
    <link href="__PUBLIC__/css/public.css" rel="stylesheet" type="text/css"/>
	
</head>
<body>
<div class="layui-conter">
    <div class="layui-col-md12">
        <div class="navigation">
            <span>教务></span><span>班级管理></span><span>假日管理</span>
        </div>

        <div class="white-conter">
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="title-blue"><b>假日管理</b></div>
                    <div class="layui-card-body addPadding">
                        <form class="layui-form" action="" lay-filter="component-form-group">
                            <div class=" layui-row" style="margin-top: 20px">
                                <div class=" layui-col-md4" style="width: 30%;">
                                    <label class="layui-form-label">假日名称：</label>
                                    <div class="layui-input-block">
                                        <input type="text" id="holiday_name" placeholder="请输入..." class="layui-input" >
                                    </div>
                                </div>
                                <div class=" layui-col-md4" style="width: 30%;">
                                    <label class="layui-form-label">起始时间：</label>
                                    <div class="layui-input-block">
                                    	<input type="text" class="layui-input" id="startTime" placeholder="起始时间">
																		<i class="layui-icon layui-icon-date" style="font-size: 16px; color: #666666;position: absolute;top: 0;right: 15px;"></i>  
                                    </div>
                                </div>
                                <div class=" layui-col-md4" style="width: 30%;">
                                    <label class="layui-form-label">截止日期：</label>
                                    <div class="layui-input-block">
                                        <input type="text" class="layui-input" id="endTime" placeholder="截止日期">
																		<i class="layui-icon layui-icon-date" style="font-size: 16px; color: #666666;position: absolute;top: 0;right: 15px;"></i> 
                                    </div>
                                </div>
																<div class="layui-inline add" style="margin-left: 20px;">
																	<button class="layui-btn layui-btn-sm layui-btn-normal" lay-submit="" onclick="add()" >添加</button>
																</div>
                            </div>
                        </form>
                    </div>
                </div>
                <div class="layui-col-md12">
                    <div class="layui-card">
                        <div class="layui-card-body"  style="border-bottom:none;">
                            <table  class="layui-hide" id="test-table-operate" lay-filter="test-table-operate"></table>
                            <div class="layui-form layui-border-box layui-table-view" lay-filter="LAY-table-1">
                                <div class="layui-table-box" style="margin-bottom: 20px">
                                    <div class="layui-table-body layui-table-main">
                                        <table cellspacing="0" cellpadding="0" border="0" class="layui-table">
                                            <thead>
                                            <tr>
                                                <th data-field="holidayName" style="padding-left: 60px;"  >
                                                    <div class="layui-table-cell laytable-cell-holidayName">
                                                        <span>假日名称</span>
                                                    </div>
                                                </th>
                                                <th data-field="startTime">
                                                    <div class="layui-table-cell laytable-cell-startTime" align="center">
                                                        <span>起始时间</span>
                                                    </div>
                                                </th>
                                                <th data-field="endTime">
                                                    <div class="layui-table-cell laytable-cell-endTime" align="center">
                                                        <span>截止日期</span>
                                                    </div>
                                                </th>
                                                <th data-field="operation">
                                                    <div class="layui-table-cell laytable-cell-1-operation" align="center">
                                                        <span>操作</span>
                                                    </div>
                                                </th>
                                            </tr>
                                            </thead>
                                            <tbody>
                                           <foreach name="holiday_data" item="h">
																							<tr data-index="13" class="">
																								<td data-field="holidayName" style="padding-left: 60px;"  align="center">
																									<div class="layui-table-cell laytable-cell-holidayName">{$h.holiday_name}</div>
																								</td>
																								<td data-field="startTime" align="center">
																									<div class="layui-table-cell laytable-cell-startTime">{$h.start_time}</div>
																								</td>
																								<td data-field="endTime" align="center">
																									<div class="layui-table-cell laytable-cell-endTime">{$h.next_time}</div>
																								</td>
																								<td data-field="operation" align="center">
																									<div class="layui-table-cell laytable-cell-1-operation">
																										<button data-method="offset" data-type="auto" data-id="{$h.id}" class="img-but edit-img"></button>
																										<button data-method="offset" data-type="auto" onclick="holiday_del('holiday',{$h.id})"  class="img-but del-img"></button>
																									</div>
																								</td>
																							</tr>
																							</foreach>
                                            </tbody>
                                        </table>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script src="__PUBLIC__/js/layui.all.js"></script>
<script src="__PUBLIC__/js/jquery.js"></script>
<script>
    layui.use( ['form','layer','laydate','element'], function(){
        var laydate = layui.laydate;
        //执行一个laydate实例
        laydate.render({
            elem: '#startTime' //起始时间
        });
		laydate.render({
			elem: '#endTime' //截止时间
		});
		var  form = layui.form
				, $ = layui.jquery
				,layer = layui.layer
				,element = layui.element
				, laydate = layui.laydate;
		element.render();
		//触发事件
		        var active = {
		            offset: function(othis){
		                var type = othis.data('type')
		                    ,text = othis.text();
		                layer.open({
		                    type: 1,
		                    title: false,
		                    area: ['600px', '300px'],
		                    shadeClose: true,
		                    skin: 'layer-look',
		                    content:'<form class="layui-form layer_notice"  action="{:U("Classsetting/edit")}" method="post" lay-filter="test1" >' +
		                    '</form>'
		                });
		
		            }
		        };
		        $('.edit-img').on('click', function(){
		            var othis = $(this), method = othis.data('method'),id = othis.data('id');
		            active[method] ? active[method].call(this, othis) : '';
								$.post("{:U('Classsetting/search')}",{id:id},function(data){
									console.log(data);
									var html= '<div class="layui-col-md12 msgCont">' +
											'<div class="layui-col-md6">' +
											'<input type="hidden" name="id" value="'+data.id+'">' +
											'<div class="listTop"><div class="layui-col-md5">节日名称</div><div class="layui-col-md6">  <input type="text" name="holiday_name" value="'+data.holiday_name+'" class="layui-input" ></div></div>' +
											'<div class="listTop"><div class="layui-col-md5">起始时间</div><input type="text" class="layui-input" id="start_time" name="start_time" value="'+data.start_time+'" placeholder="起始时间"></div>' +
											'<div class="listTop"><div class="layui-col-md5">截止日期</div><input type="text" class="layui-input" id="next_time" name="next_time" value="'+data.next_time+'" placeholder="截止日期"></div>' +
											'</div>  <div class="layui-col-md12">\n' +
											'                            <div class="button-block">\n' +
											'                                <button class="layui-btn layui-btn-xs layui-btn-normal" lay-submit="" onclick="save()">保存</button>\n' +
											'                            </div>\n' +
											'                        </div>' +
											'</div>'
									$('.layer_notice').append(html);
									
									//执行一个laydate实例
									laydate.render({
											elem: '#start_time' //指定元素
									});
									laydate.render({
											elem: '#next_time' //指定元素
									});
								})
		        });
    });
</script>
<script>
	function add(){
		var holiday_name = $("#holiday_name").val();
		var start_time = $("#startTime").val();
		var next_time = $("#endTime").val();
		$.post("{:U('Classsetting/holidaySet')}",{holiday_name:holiday_name,start_time:start_time,next_time:next_time},function(data){
			if(data==1){
				alert('新增成功');
				window.location.href="{:U('Classsetting/holidaySet')}";
			}else if(data==0){
				alert('新增失败');
			}
		})
	}
function holiday_del(model,id){
	$.post("{:U('Index/del')}",{model:model,id:id},function(data){
		if(data==1){
			alert('删除成功!');
			window.location.href="{:U('Classsetting/holidaySet')}";
		}else{
			alert('删除失败');
		}
	})
}
</script>
</html>